<?php 
ob_start(); session_start();
require_once('config/setting.php');
if (!$_SESSION['userid'])
{
	header('location: login.php');
	
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<title>The Century - Admin Panel</title>
	<style>
        .topmenu{
            font-family:arial;
			font-weight:bold;
            font-size:16px;
            color:#FFFFFF;
            text-decoration:none;
        }
        .topmenu:hover{
            font-family:arial;
			font-weight:bold;
            font-size:16px;
            color:#FFFFFF;
            text-decoration:underline;
        }
    </style>
</head>
<body>
<table width="100%">
<div style="padding:10px; font-size:20px; font-family:verdana;"><span>THE CENTURY <span style="font-size:14px">Admin Panel</span></span></div>

<tr>
	<td style="width:100%; height:auto; ">
	  <table  style="width:100%; height:100%" border="0">
		<tr>
			<td style="background:#FF0000; height:71px;">
			   <div align="center">	
				   <table style="width:960px;" cellpadding="0" cellspacing="0" border="0">
						<tr>
							<td style="height:42px; padding-top:15px"  >
								<table align="center" cellpadding="0" cellspacing="0" border="0">
									<tr>
										<td style="font-weight:bold; color:#FFFFFF">
                                        	<a href="view-customers.php" class="topmenu">View Customers</a> &nbsp;|&nbsp; 
											<a href="reports.php" class="topmenu">Reports</a> &nbsp;|&nbsp; 
                                            <a href="reservation.php" class="topmenu">Reservation</a> &nbsp;|&nbsp; 
                                            <a href="slots.php" class="topmenu">Slots</a> &nbsp;|&nbsp;  
                                            <a href="question.php" class="topmenu">Question</a> &nbsp;|&nbsp;  
                                            <a href="menus.php" class="topmenu">Menus</a> &nbsp;|&nbsp;  
                                            <a href="logout.php" class="topmenu">Logout</a> 
                                        </td>
									</tr>
								</table>							
                             </td>
						</tr>
					</table>			
				</div>			
              </td>
		</tr>	
	</table></td>
</tr>
<!--content-->
<tr>
	<td style="width:100%; background:url(../images/w_bgr.jpg); height:500px; font-family:arial; font-size:12px" valign="top" align="center">
    	<form name="mealform" method="post">
    	<div align="center">
        	<input type="button" value="Customer Account Status Report" onClick="location.href='reports.php?action=customer status'" style="height:40px">
			<input type="button" value="Reservation Report" onClick="location.href='reports.php?action=reservation report'" style="height:40px"><? echo''.$_POST['tabless'].'';?>
            <br><br>
        </div>
        <? if($_GET['action'] == 'reservation report'){ 
         echo '<select name="tabless" style="width:200px" >
		 					<option selected> </option>
                            <option>Confirmed</option>
                            <option>Unconfirmed</option>
                            <option>Cancelled</option>
                            <option>5:00PM</option>
                            <option>7:00PM</option>
                        </select>
						
						<input name = "Go" value="Go"  type="submit" style="height:20px">
						';
		}
		else if($_GET['action'] == 'customer status')  {
			
			echo '<select name="tablesss" style="width:200px" >
		 					<option selected> </option>
                            <option>Confirmed</option>
                            <option>Unconfirmed</option>
                            <option>Cancelled</option>
                            </select>
						
						<input name = "Go" value="Go"  type="submit" style="height:20px">
						';
			
		
		
		}
		
		
		
       ?>
       
        
        
        
      <div style="width:600px;"  align="left">
            <? if($_GET['action'] == 'customer status'){ ?>
            	<table cellpadding="0" cellspacing="0" width="700px" style="font-size:12px; border:solid 1px #CCCCCC; "  >
                	<tr>
                    	<td width="60" height="30px" align="center" bgcolor="#999999" style="border-right:solid 1px #cccccc; color:#FFF"><b>Customer ID</b></td>
                        <td width="211" height="30px" align="center" bgcolor="#999999" style="border-right:solid 1px #cccccc; color:#FFF"><b>Name</b></td>
                       <? if($_POST['tablesss']=='Confirmed'){
						echo'	 <td width="87" align="center" bgcolor="#999999" style="color:#FFFFFF; border-right:solid 1px #cccccc; " ><b>Total Confirmed Reservations</b></td>';   
					   }
					   else if($_POST['tablesss']=='Unconfirmed'){
						echo'	 <td width="87" align="center" bgcolor="#999999" style="color:#FFFFFF; border-right:solid 1px #cccccc; " ><b>Total Unconfirmed Reservations</b></td>';   
					   }
					   
					   else if($_POST['tablesss']=='Cancelled'){
						echo'	 <td width="87" align="center" bgcolor="#999999" style="color:#FFFFFF; border-right:solid 1px #cccccc; " ><b>Total Cancelled Reservations</b></td>';   
					   }
                         
					 else{
					echo'	 <td width="87" align="center" bgcolor="#999999" style="color:#FFFFFF; border-right:solid 1px #cccccc; " ><b>Total Reservations</b></td>';
					 }
                         ?>
                        <td width="99" align="center" bgcolor="#999999" style="color:#FFFFFF; border-right:solid 1px #cccccc; " ><b>Last Reservation Date</b></td>
                        <td width="63" align="center" bgcolor="#999999" style="color:#FFFFFF; border-right:solid 1px #cccccc; "><b>Status</b></td>
                        <td width="78" align="center" bgcolor="#999999" style="color:#FFFFFF"><b>Date Active</b></td>
                    </tr>
        			<?php 
						function getreservation($tmpid){
							if($_POST['tablesss']=='Confirmed'){
		$result = mysql_query("select * from tbl_reservation where mid = '$tmpid' and status='2'") or die (mysql_error());}
		
		else if($_POST['tablesss']=='Unconfirmed'){
		$result = mysql_query("select * from tbl_reservation where mid = '$tmpid' and status='1'") or die (mysql_error());}
		else if($_POST['tablesss']=='Cancelled'){
		$result = mysql_query("select * from tbl_reservation where mid = '$tmpid' and status='0'") or die (mysql_error());}
		else{
							$result = mysql_query("select * from tbl_reservation where mid='$tmpid'") or die (mysql_error());}
							$total = mysql_num_rows($result);
							return $total;
						}
						
						function getlast($tmpid){
														
							$result = mysql_query("select * from tbl_reservation where mid='$tmpid' order by dateposted DESC limit 1" ) or die (mysql_error());
							if ($row = mysql_fetch_array($result)){							
								$lastdate = date("M j, Y", $row['dateposted']); 
							}else{
								$lastdate = 'No Reservation';
							}
							return $lastdate;
						}
					
	
		
	
	
						$result = mysql_query("select * from tbl_members") or die (mysql_error());
						while ($row = mysql_fetch_array($result)){
							$id = $row['id'];
							$customer = $row['firstname'].' '.$row['lastname'];
							$active = $row['active'];
							$dateactive = date("M j, Y", $row['dateposted']); 
							if($active=='0'){
							   $status = 'Deleted';	
							}else{
							   $status = 'Active';		
							}
							$totalreservation = getreservation($id);
							$lastreservation = getlast($id);
							echo '<tr>
										<td height="26px" style="border-right:solid 1px #cccccc; border-bottom:dashed 1px #CCCCCC" align="center" >'.$id.'</td>
										<td style="border-right:solid 1px #cccccc; border-bottom:dashed 1px #CCCCCC; padding-left:10px" align="left" >'.$customer.'</td>
										<td style="border-right:solid 1px #cccccc; border-bottom:dashed 1px #CCCCCC; padding-left:10px" align="left" >'.$totalreservation.'</td>
										<td style="border-right:solid 1px #cccccc; border-bottom:dashed 1px #CCCCCC; padding-left:10px" align="left" >'.$lastreservation.'</td>
										<td style="border-right:solid 1px #cccccc; border-bottom:dashed 1px #CCCCCC; padding-left:10px" align="left" >'.$status.'</td>
										<td style="border-bottom:dashed 1px #CCCCCC; padding-left:10px" align="left" >'.$dateactive.'</td>
									</tr>';
									
							
						}
                    ?>					
                </table>
           <? } ?>
           
            
            
            <? if($_GET['action'] == 'reservation report'  ){ ?>
            
            	<table cellpadding="0" cellspacing="0" width="700px" style="font-size:12px; border:solid 1px #CCCCCC; "  >
                	<tr>
                    	<td width="50" height="30px" align="center" bgcolor="#999999" style="border-right:solid 1px #cccccc; color:#FFF"><b>Reservation ID </b></td>
                    	<td width="100" height="30px" align="center" bgcolor="#999999" style="border-right:solid 1px #cccccc; color:#FFF"><b>Transaction Date </b></td>
                        <td width="220" align="center" bgcolor="#999999" style="color:#FFFFFF; border-right:solid 1px #cccccc; " ><b>Reservation Date</b></td>
                        <td width="134" align="center" bgcolor="#999999" style="color:#FFFFFF; border-right:solid 1px #cccccc; "><b>Customer</b></td>
                        <td width="94" align="center" bgcolor="#999999" style="color:#FFFFFF"><b>Status</b></td>
                    </tr>
                    <?php 
						function getname($clk){
							$nresult = mysql_query("select * from tbl_members where id='$clk'") or die (mysql_error());
							if($nrow = mysql_fetch_array($nresult)){
								$fullname = $nrow['firstname'].' '.$nrow['lastname'];
							}
							return $fullname;
						}
					
				// 	<br>

if($_POST['tabless'] == 'Confirmed'){
$result = mysql_query("select * from tbl_reservation where status='2'") or die (mysql_error());
}
else if($_POST['tabless'] == 'Unconfirmed'){
	$result = mysql_query("select * from tbl_reservation where status='1'") or die (mysql_error());
}
else if($_POST['tabless'] == 'Cancelled'){
	$result = mysql_query("select * from tbl_reservation where status='0'") or die (mysql_error());
	
}

			else{
						$result = mysql_query("select * from tbl_reservation") or die (mysql_error());}
					
					
					
					
					
					
					
						while ($row = mysql_fetch_array($result)){
							$id = $row['id'];
							$customer = getname($row['mid']);
							$tdate = date("F j, Y", $row['dateposted']); 
							$rdate = $row['selected_date'];
							$rtime = $row['selected_time'];
							$rtable = $row['selected_table'];
							$status = $row['status'];
							if($status=='0'){
								$statdesc = 'Cancelled';	
							}
							if($status=='1'){
								$statdesc = 'Unconfirmed';	
							}
							if($status=='2'){
								$statdesc = 'Confirmed';	
							}							
							
							echo '<tr>
										<td height="26px" style="border-right:solid 1px #cccccc; border-bottom:dashed 1px #CCCCCC" align="center" >'.$id	.'</td>
										<td style="border-right:solid 1px #cccccc; border-bottom:dashed 1px #CCCCCC" align="center" >'.$tdate.'</td>
										<td style="border-right:solid 1px #cccccc; border-bottom:dashed 1px #CCCCCC; padding-left:10px" align="left" >'.$rdate.', '.$rtime.', '.$rtable.'</td>
										<td style="border-right:solid 1px #cccccc; border-bottom:dashed 1px #CCCCCC; padding-left:10px" align="left" >'.$customer.'</td>
										<td style="border-bottom:dashed 1px #CCCCCC; padding-left:10px" align="left" >'.$statdesc.'</td>
									</tr>';
									
							
						}
                    ?>
                </table>
					            
            <? } ?>
            
            
        </div>
        </form>
     </td>
</tr>
<!--footer-->
<tr>
	<td style="width:100%;"><table style="width:100%; height:100%">
		<tr>
			<td style="width:50%;"><img alt="" src="../images/spacer.gif" width="1" height="1"></td>
			<td style="width:766px;"><table style="width:766px;">
				<tr><td class="end"><table>
					
				</table></td></tr>
				<tr>
				  <td class="end">&nbsp;</td>
			  </tr>
			</table></td>
			<td style="width:50%;"><img alt="" src="../images/spacer.gif" width="1" height="1"></td>
		</tr>
	</table></td>
</tr>
</table>
<script>
	function confirmation(){
		var answer=confirm("Are you sure you want to remove this item?")
		if(answer){
			return true
		}else{
			return false
		}
	}
	
	function selectmeal(clk,price,nid){
		var nclk = document.getElementById(clk);
		if(nclk.checked==true){
			nclk.value=nid;
		}else{	
			nlck.value='';
		}
	}	
</script>

</body>
</html>
